package com.lhb.user.controller;

import com.lhb.common.model.UnifyResponseObject;
import com.lhb.user.model.ModifyEmailModel;
import com.lhb.user.model.ModifyPasswordModel;
import com.lhb.user.model.Passenger;
import com.lhb.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 86131
 * @version 1.0
 * @description
 * @date 2025/8/1 下午3:04
 */
@RestController
@RequestMapping("/userinfo")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;

    @PostMapping("/modify_password")
    public UnifyResponseObject modifyPassword(@RequestBody ModifyPasswordModel modifyPasswordModel) throws Exception {

        userInfoService.modifyPassword(modifyPasswordModel);

        return UnifyResponseObject.success("密码修改成功");

    }
    @PostMapping("/modify_email")
    public UnifyResponseObject modifyEmail(@RequestBody ModifyEmailModel modifyEmailModel) throws Exception {

        userInfoService.modifyEmail(modifyEmailModel);

        return UnifyResponseObject.success("邮箱修改成功");
    }

    @PostMapping("/addPassenger")
    public UnifyResponseObject<Passenger> addPassenger(@RequestBody Passenger passenger)
    {
        Passenger passenger1=  userInfoService.addPassenger(passenger);

        return UnifyResponseObject.success(passenger1,"保存成功");
    }

    @GetMapping("/getPassenger")
    public UnifyResponseObject<List<Passenger>> getPassenger()
    {
        List<Passenger> passengers= userInfoService.getPassenger();

        return UnifyResponseObject.success(passengers,"");
    }

    @DeleteMapping("/deletePassenger/{id}")
    public UnifyResponseObject deletePassenger(@PathVariable("id") Long id)
    {
        userInfoService.deletePassenger(id);
        return UnifyResponseObject.success("删除成功");
    }

}
